package com.ymatou.iapi.liveinfo.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveinfo.parameter.GetActivityByIdBean;
import com.ymatou.iapi.liveinfo.service.GetActivityByIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.database.mongo.jproduct.LiveProductsWapper;
import com.ymttest.database.mongo.jproduct.LivesWapper;
import com.ymttest.database.mongo.jproduct.ProductsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*获取直播详情
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetActivityById{
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	private static GetActivityByIdBean bean;
	private static GetActivityByIdCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取直播详情");
	}

	@Before
	public void caseUp() {
		bean=new GetActivityByIdBean();
		call=new GetActivityByIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetActivityById_001() {
		Logger.start(true,"获取直播详情");
		try {
			LivesWapper wapper = new LivesWapper();
		    Integer lid=LiveCallService.createLiveInProgress(sellerName,sellerId).getJSONObject("Data").getInt("ActivityId");
		    String cover="http://m.ymatou.com/"+TestDataManager.getRandomUUID().toString();
			wapper.updateCover(lid.toString(), cover);
			LiveCallService.CreateLivesProductByLivesId(sellerId,sellerName,lid);
			Thread.sleep(1000); 
			bean.setActivityId(lid);
			call.setData(bean);
			call.callService();	
			GetVerify(bean.getActivityId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void GetVerify(Integer lid) throws Exception
	{
		LivesWapper wapper=new LivesWapper();
		if(lid!=0)
       {
            Map<String,Object> lst=wapper.getLivesBylid(lid);
			Logger.verifyEquals(200, call.getCode(), "判断code是否为200");
			Logger.verifyEquals("操作成功",call.getMsg(), "判断Msg返回操作成功");
			Logger.verifyEquals(0,call.getBCode(), "判断操作成功时 业务代码是否0");
			Logger.verifyNotNull(call.getServerTime(), "判断服务器时间是否为空");
			Logger.verifyEquals(lst.get("title"), call.getData().getString("Title"), "验证直播title是否与mongodb一致");
			Logger.verifyEquals(lst.get("vcover"), call.getData().getString("VideoCover"), "验证直播VideoCover是否与mongodb一致");
			Logger.verifyEquals(lst.get("vurl"), call.getData().getString("VideoUrl"), "验证直播VideoUrl是否与mongodb一致");
			Logger.verifyEquals(lst.get("action").toString(), call.getData().getString("Action").toString(), "验证直播Action是否与mongodb一致");
			Logger.verifyEquals(lst.get("lid").toString(), call.getData().getString("ActivityId").toString(), "验证直播ActivityId是否与mongodb一致");
			Logger.verifyEquals(lst.get("name"), call.getData().getString("ActivityName"), "验证直播ActivityName是否与mongodb一致");
			Logger.verifyEquals(lst.get("pic"), call.getData().getString("ActivityPicture"), "验证直播ActivityPicture是否与mongodb一致");

			Logger.verifyEquals((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(lst.get("add")).toString(), call.getData().getString("AddTime").toString(), "验证直播AddTime是否与mongodb一致");
			Logger.verifyEquals(lst.get("country"), call.getData().getString("Country"), "验证直播Country是否与mongodb一致");
			Logger.verifyEquals((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(lst.get("end")), call.getData().getString("EndTime"), "验证直播EndTime是否与mongodb一致");
			Logger.verifyEquals(lst.get("sid").toString(), call.getData().getString("SellerId").toString(), "验证直播SellerId是否与mongodb一致");
			Logger.verifyEquals(lst.get("addr"), call.getData().getString("ShopAddress"), "验证直播ShopAddress是否与mongodb一致");
			Logger.verifyEquals((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(lst.get("start")), call.getData().getString("StartTime"), "验证直播StartTime是否与mongodb一致");
			Logger.verifyEquals(lst.get("content"), call.getData().getString("ActivityInfo"), "验证直播ActivityInfo是否与mongodb一致");
			String start=(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(lst.get("start"));
			String end=(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(lst.get("end"));
			Logger.verifyEquals(lst.get("cover"), call.getData().getString("LiveCover"), "验证直播LiveCover是否与mongodb一致");
			
		 }
	}
}
